/**
 ******************************************************************************
 * File Name          : USART.h
 * Description        : This file provides code for the configuration
 *                      of the USART instances.
 ******************************************************************************
 * @attention
 *
 * <h2><center>&copy; Copyright (c) 2023 STMicroelectronics.
 * All rights reserved.</center></h2>
 *
 * This software component is licensed by ST under BSD 3-Clause license,
 * the "License"; You may not use this file except in compliance with the
 * License. You may obtain a copy of the License at:
 *                        opensource.org/licenses/BSD-3-Clause
 *
 ******************************************************************************
 */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __usart_H
#define __usart_H
#ifdef __cplusplus
extern "C"
{
#endif

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* USER CODE BEGIN Includes */
#include "cicrleQueue.h"
#include <stdio.h>
#include <string.h>
/* USER CODE END Includes */

extern UART_HandleTypeDef huart1;

/* USER CODE BEGIN Private defines */

#define USART_BUFF_MAX 64
typedef void (UsartRecv_Callback_t *)(uint8_t *data, uint16_t len);

typedef enum
{
    PROTOCOL_STATE_START = 0,
    PROTOCOL_STATE_CMD_H = 1,
    PROTOCOL_STATE_CMD_L = 2,
    PROTOCOL_STATE_LENGTH_H = 3,
    PROTOCOL_STATE_LENGTH_L = 4,
    PROTOCOL_STATE_CHECK = 5,
    PROTOCOL_STATE_DATA = 6,
    PROTOCOL_STATE_END = 7
} te_protocol_state_t;

typedef struct my_usart
{
    uint8_t data_tmp;
    te_protocol_state_t state;
    struct valid_data_t
    {
        uint8_t buf[32];
        uint8_t len;
    }valid_data;
    uint16_t data_nums;

    p_UsartRecv_Callback;
}ts_usart_t;

/* USER CODE END Private defines */
void MX_USART1_UART_Init(void);

/* USER CODE BEGIN Prototypes */
void Usart_Enable_Interrupt(void);
void analysis_uart(ts_cicrleQueue_t *cq_in);
extern ts_cicrleQueue_t CQ_Usart_Recv;
/* USER CODE END Prototypes */

#ifdef __cplusplus
}
#endif
#endif /*__ usart_H */

/**
 * @}
 */

/**
 * @}
 */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
